﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.Serialization;
using System.Text.RegularExpressions;

namespace d39
{
    public partial class GridSave : System.Web.UI.Page
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            var grid = Grid.FromQueryString(Request.QueryString);
            var filename = "grid";
            if (grid.Name != null) filename = Regex.Replace(grid.Name, "[^a-z0-9]+", "-", RegexOptions.IgnoreCase).Trim('-'); 
            Response.ContentType = "application/xml";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + filename + ".d39");
            Response.SetCachingHeaders();
            var xmlSerializer = new XmlSerializer(typeof(Grid));
            xmlSerializer.Serialize(Response.Output, grid);
            Response.Flush();
            Response.End();
        }
    }
}